package cn.edu.scau.cmi.yangjiamin.client;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import cn.edu.scau.cmi.yangjiamin.spring.Student;
import cn.edu.scau.cmi.yangjiamin.spring.Teacher;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.text.Text;
import javafx.stage.Stage;

public class SpringClient extends Application{
	@Override
	public void start(Stage primaryStage) {
		ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");

		BorderPane pane = new BorderPane();
		HBox hbox = new HBox();
		hbox.setPadding(new Insets(10, 10, 10, 10));
		Button teaBt = new Button("教师信息");
		Button stuBt = new Button("学生信息");
		hbox.getChildren().addAll(teaBt, stuBt);
		Text text =  new Text(100, 100, "显示结果");
		teaBt.setOnAction(e->{
			Teacher tea = (Teacher)applicationContext.getBean("teacher");
			text.setText(tea.toString());
		});
		
	
		stuBt.setOnAction(e->{ 
			Student stu = (Student)applicationContext.getBean("student");
			text.setText(stu.toString());
		});
		pane.setTop(hbox);
		pane.setCenter(text);
		Scene scene = new Scene(pane, 600, 500);
		primaryStage.setTitle("SpringClient");
		primaryStage.setScene(scene);
		primaryStage.show();
	}

}
